package com.gdones.gpt.timeTasks;

import com.gdones.gpt.bus.gptstaff.mapper.StaffModeGrantMapper;
import com.gdones.gpt.bus.webAccount.service.IGptWebaccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * GPT定时任务
 * 2023/6/9
 */
@Component
public class GptWebAccountTasks {

    @Autowired
    private StaffModeGrantMapper staffModeGrantMapper;

    @Resource(name = "gptWebaccountServiceImpl")
    private IGptWebaccountService gptWebaccountServiceImpl;

    /**
     * 每天晚上12点，重置用户使用次数
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void resetStaffUessLess(){
        System.err.println("-----定时任务执行：重置每个人每日调用额度");
        int i = staffModeGrantMapper.updateAllStaffUseLess();
    }


    /**
     * 每天晚上凌晨1点，更新openai的额度
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void updateOpenai(){
        System.err.println("-----定时任务执行：更新openai的额度");
        gptWebaccountServiceImpl.updateAllGptLimit();
    }

}
